// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class eggMoveAction extends cc.Component {

    onLoad() {
        this.moveAction();
    }

    moveAction(){
        let x = this.node.x + cc.winSize.height / 2 + this.node.y;
        let distance = Math.sqrt(2) * (cc.winSize.height / 2 + this.node.y);
        cc.tween(this.node).to(distance / 40, {
            position : cc.v2(x,-cc.winSize.height / 2)
        }).call(()=>{
            this.node.x -= (cc.winSize.height + 150);
            this.node.y = cc.winSize.height / 2 + 150;
            this.moveAction();
        }).start();
    }
    // update (dt) {
    //     if(this.node.y <= -cc.winSize.height / 2){
    //         this.node.y = cc.winSize.height / 2;
    //         this.node.x -= cc.winSize.height / 2;
    //     }
    //     this.node.x += 1;
    //     this.node.y -= 1;
    // }
}
